package com.liziyi0914.morearmor.effect;

import com.liziyi0914.morearmor.PlayerManager;
import com.liziyi0914.morearmor.Utils;
import com.liziyi0914.morearmor.event.Listener;
import com.liziyi0914.morearmor.event.entity.PlayerRespawnEvent;
import net.minecraft.entity.LivingEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.tag.ItemTags;
import net.minecraft.util.Identifier;

import java.util.function.Predicate;

public class BedEffect extends AbstractEffect {

    @Listener
    public void onRespawn(PlayerRespawnEvent e) {
        if (!predicateArmor().test(e.getPlayer())) {
            return;
        }
        final ServerPlayerEntity player = PlayerManager.get(e.getPlayer().getUuid());
        if (!e.getDimension().equals(new Identifier("minecraft:overworld"))) {
            player.setHealth(0.0F);
        }
    }

    @Override
    public Predicate<LivingEntity> predicateArmor() {
        return Utils.hasItemTagArmor(ItemTags.BEDS);
    }
}
